//var successinfo = "*通过验证!";
var successinfo = "OK!";

function charge_check() {
	
	$("#chargeform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			chargeName: {
				required: true,
				maxlength: 100
			},
			price: {
				required: true,
				number: true
			},
			description: {
				maxlength: 500
			}						
		},
		messages: {
			chargeName: {
				required: "*套餐名称不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			price: {
				required: "*套餐价格不能为空",
				number: "*请输入数字"
			},
			description: {
				maxlength: $.format("*长度最大为{0}")
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		},
		ignoreTitle: true,
		
	});
	
	$('input').blur(function() { 
		$("#chargeform").validate().element(this);      
    });   
}

function user_check() {

	jQuery.validator.addMethod("isMobile", function(value, element){
    	var length = value.length;
    	return this.optional(element) || (length == 11 && /^1[358]\d{9}$/.test(value));}, "*请填写正确的手机号码");

	$("#userform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			userName: {
				required: true,
				rangelength: [8,12],
				remote: "../uservalid.do",
			},
			password: {
				required: true, 
				rangelength: [6,20]
			},
			passwordAgain: {
				required: true,
				equalTo: "#password"
			},
			husband: {
				required: true,
				maxlength: 20
			},
			wife: {
				required: true,
				maxlength: 20
			},
			mobile: {
				required: true,
				isMobile: true
			},
			email: {
				email: true,
			},
			province: {
				required: true,
			},
			city: {
				required: true,
			},
			notes: {
				maxlength: 500
			}			
		},
		messages: {
			userName: {
				required: "*用户名不能为空",
				rangelength: $.format("*用户名需在{0}-{1}个字符之间"),
				remote: $.format("*用户{0}已经被占用")
			},
			password: {
				required: "*密码不能为空", 
				rangelength: $.format("*密码需在{0}-{1}个字符之间"),
			},
			passwordAgain: {
				required: "*密码验证不能为空",
				equalTo: "*两次输入的密码不一致"
			},
			husband: {
				required: "*新郎名不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			wife: {
				required: "*新娘名不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			mobile: {
				required: "*手机号不能为空"
			},
			email: {
				email: "*邮箱地址不正确(例如：ecp@ecp.com)",
			},
			province: {
				required: "*省份不能为空",
			},
			city: {
				required: "*地市不能为空",
			},
			notes: {
				maxlength: $.format("*长度最大为{0}")
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		} 
	});
	$('input').blur(function() { 
		$("#userform").validate().element(this);      
    }); 
}

function adminuser_check() {

	jQuery.validator.addMethod("isMobile", function(value, element){
    	var length = value.length;
    	return this.optional(element) || (length == 11 && /^1[358]\d{9}$/.test(value));}, "*请填写正确的手机号码");
    	
    jQuery.validator.addMethod("isPhone", function(value, element){
    	var length = value.length;
    	return this.optional(element) || (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(value));}, "*请填写正确的电话号码(例如：0571-81951139)");

	$("#adminuserform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			"adminUser.adminUserName": {
				required: true,
				rangelength: [8,12],
				remote: "../adminuservalid.do"  //ajax验证
			},
			"adminUser.password": {
				required: true, 
				rangelength: [6,20]
			},
			password1: {
				required: true,
				equalTo: "#password"
			},
			"adminUser.companyName": {
				required: true,
				maxlength: 100
			},
			"adminUser.telephone": {
				required: true,
				isPhone: true
			},
			"adminUser.contact": {
				required: true,
				maxlength: 20
			},
			"adminUser.mobile": {
				required: true,
				isMobile: true
			},
			"adminUser.province": {
				required: true,
			},
			"adminUser.city": {
				required: true,
			},
			"adminUser.address": {
				required: true,
				maxlength: 50
			},	
			"adminUser.companyType": {
				required: true
			},
			"adminUser.state": {
				required: true
			},
			"adminUser.description": {
				maxlength: 500
			}	
		},
		messages: {
			"adminUser.adminUserName": {
				required: "*用户名不能为空",
				rangelength: $.format("*用户名需在{0}-{1}个字符之间"),
				remote: $.format("*用户{0}已经被占用")
			},
			"adminUser.password": {
				required: "*密码不能为空", 
				rangelength: $.format("*密码需在{0}-{1}个字符之间"),
			},
			password1: {
				required: "*密码验证不能为空",
				equalTo: "*两次输入的密码不一致"
			},
			"adminUser.companyName": {
				required: "*公司名不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			"adminUser.telephone": {
				required: "*公司电话不能为空",
			},
			"adminUser.contact": {
				required: "*联系人不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			"adminUser.mobile": {
				required: "*联系人手机号不能为空"
			},
			"adminUser.province": {
				required: "*省份不能为空",
			},
			"adminUser.city": {
				required: "*地市不能为空",
			},
			"adminUser.address": {
				required: "*地址不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			"adminUser.companyType": {
				required: "*公司类别不能为空"
			},
			"adminUser.state": {
				required: "*状态不能为空"
			},
			"adminUser.description": {
				maxlength: $.format("*长度最大为{0}")
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		},
		errorPlacement: function(error, element) {
		    if ( element.is(":radio") )
		        error.appendTo( element.parent() );
		    else if ( element.is(":checkbox") )
		        error.appendTo ( element.next() );
		    else
		        error.appendTo( element.parent() );
		}
	});
	$('input').blur(function() { 
		$("#adminuserform").validate().element(this);      
    }); 
    
}

function history_check() {

	$("#historyform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			userName: {
				required: true,
				rangelength: [8,12],
				remote: "../historyvalid.do"  //ajax验证
			},
			price: {
				required: true,
				number: true
			},
			count: {
				required: true,
				number: true
			}			
		},
		messages: {
			userName: {
				required: "*用户名不能为空",
				rangelength: $.format("*用户名需在{0}-{1}个字符之间"),
				remote: $.format("*用户{0}不存在")
			},
			price: {
				required: "*价格不能为空",
				number: "*请输入数字"
			},
			count: {
				required: "*数量不能为空",
				number: "*请输入数字"
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		} 
	});
	
	$('input').blur(function() { 
		$("#historyform").validate().element(this);      
    }); 
    
}

function order_check() {

	jQuery.validator.addMethod("isMobile", function(value, element){
    	var length = value.length;
    	return this.optional(element) || (length == 11 && /^1[358]\d{9}$/.test(value));}, "*请填写正确的手机号码");
    	
    jQuery.validator.addMethod("isCode", function(value, element){
    	var length = value.length;
    	return this.optional(element) || (/^([0-3]|[5-9]){3}$/.test(value));}, "*请填写正确3定位码(数字4不能出现,例如：168)");

	$("#orderform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			"user.userName": {
				required: true,
				rangelength: [8,12],
				remote: "../orderuservalid.do"  //ajax验证
			},
			"user.password": {
				required: true, 
				rangelength: [6,20]
			},
			password1: {
				required: true,
				equalTo: "#password"
			},
			"user.husband": {
				required: true,
				maxlength: 20
			},
			"user.wife": {
				required: true,
				maxlength: 20
			},
			"user.mobile": {
				required: true,
				isMobile: true
			},
			"user.email": {
				email: true,
			},
			"user.province": {
				required: true,
			},
			"user.city": {
				required: true,
			},
			"user.notes": {
				maxlength: 500
			},	
			"orders.chargeId": {
				required: true
			},
			"orders.orderType": {
				required: true
			},
			"orders.payState": {
				required: true
			},
			effectTime: {
				required: true,
				dateISO:true,
			},
			"orders.code": {
				required: true,
				isCode: true,
				remote: "../ordercodevalid.do"  //ajax验证
			},
			"orders.notes": {
				maxlength: 500
			},
			"orders.isUsed": {
				required: true
			}	
		},
		messages: {
			"user.userName": {
				required: "*用户名不能为空",
				rangelength: $.format("*用户名需在{0}-{1}个字符之间"),
				remote: $.format("*用户{0}已经被占用")
			},
			"user.password": {
				required: "*密码不能为空", 
				rangelength: $.format("*密码需在{0}-{1}个字符之间"),
			},
			password1: {
				required: "*密码验证不能为空",
				equalTo: "*两次输入的密码不一致"
			},
			"user.husband":  {
				required: "*新郎名不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			"user.wife": {
				required: "*新娘名不能为空",
				maxlength: $.format("*长度最大为{0}")
			},
			"user.mobile": {
				required: "*联系人手机号不能为空"
			},
			"user.email": {
				email: "*邮箱地址不正确(例如：ecp@ecp.com)",
			},
			"user.province": {
				required: "*省份不能为空",
			},
			"user.city": {
				required: "*地市不能为空",
			},
			"user.notes": {
				maxlength: $.format("*长度最大为{0}")
			},
			
			"orders.chargeId": {
				required: "*套餐不能为空"
			},
			"orders.orderType": {
				required: "*订单类型不能为空"
			},
			"orders.payState": {
				required: "*支付状态不能为空",
			},
			effectTime: {
				required: "*生效时间不能为空",
				dateISO:"*请输入正确的时间格式，例如：2009-06-23，1998/01/22"
			},
			"orders.code": {
				required: "*定位码不能为空",
				remote: $.format("*定位码{0}已被占用")
			},
			"orders.notes": {
				maxlength: $.format("*长度最大为{0}")
			},
			"orders.isUsed": {
				required: "*使用状态不能为空",
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		} 
	});
	$('input').blur(function() { 
		$("#orderform").validate().element(this);      
    }); 
    /*
    errorPlacement: function(error, element) {
	    if ( element.is(":radio") )
	        error.appendTo( element.parent().next().next() );
	    else if ( element.is(":checkbox") )
	        error.appendTo ( element.next() );
	    else
	        error.appendTo( element.parent().next() );
	}
	*/
}

function password_check() {

	$("#passwordform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			password: {
				required: true, 
				rangelength: [6,20]
			},
			password1: {
				required: true, 
				rangelength: [6,20]
			},
			password2: {
				required: true,
				equalTo: "#password1"
			}	
		},
		messages: {
			password: {
				required: "*原密码不能为空",
				rangelength: $.format("*密码需在{0}-{1}个字符之间"),
			},
			password1: {
				required: "*新密码不能为空",
				rangelength: $.format("*密码需在{0}-{1}个字符之间"),
			},
			password2: {
				required: "*密码验证不能为空",
				equalTo: "*两次输入的密码不一致"
			}
		},
		success: function(label) {     
			label.addClass("valid").text("OK!"); 
		} 
	});
	
	$('input').blur(function() { 
		$("#passswordform").validate().element(this);      
    }); 
    
}

function suggestion_check() {

	$("#suggestionform").validate({
	    submitHandler: function(form){   
      		form.submit();
		}, 
		rules: {
			"suggestion.content": {
				maxlength: 500
			}
		},
		messages: {
			password: {
				maxlength: $.format("*长度最大为{0}")
			}
		},
		success: function(label) {     
			label.addClass("valid").text(successinfo); 
		} 
	});
	
	$('input').blur(function() { 
		$("#suggestionform").validate().element(this);      
    }); 
    
}